package com.ash.spel;

import org.springframework.expression.ExpressionParser;
import org.springframework.expression.ParserContext;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

import java.util.Date;
import java.util.List;

/**
 * @author Ashin
 */
public class Main {

    public static void main(String[] args) {
        Inventor inventor = new Inventor();
        inventor.setName("ash");
        inventor.setNationality("China");
        StandardEvaluationContext inventorContext = new StandardEvaluationContext();
        inventorContext.setVariable("inventor", inventor);

        ExpressionParser parser = new SpelExpressionParser();

        String randomPhrase = parser.parseExpression("ad+"+"#inventor.name+ #inventor.nationality").getValue(inventorContext,String.class);
        System.out.println(randomPhrase);
    }

    public static class Demo {
        public List<String> list;
    }

    public static class Inventor {
        private String name;

        private Date birthday;

        private String nationality;

        public Inventor() {

        }

        public Inventor(String name, Date birthday, String nationality) {
            this.name = name;
            this.birthday = birthday;
            this.nationality = nationality;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Date getBirthday() {
            return birthday;
        }

        public void setBirthday(Date birthday) {
            this.birthday = birthday;
        }

        public String getNationality() {
            return nationality;
        }

        public void setNationality(String nationality) {
            this.nationality = nationality;
        }

        @Override
        public String toString() {
            return "Inventor{" +
                    "name='" + name + '\'' +
                    ", birthday=" + birthday +
                    ", nationality='" + nationality + '\'' +
                    '}';
        }
    }
}
